from math import*
a=int(input())
if a>999 and a<=9999:
    a1=a//1000
    a2=a//100
    a3=a//10
    a4=a%10%100
    a5=a//100%10
    a6=a%1000
    a7=a//10%10
    a8=a%100
    a9=a//10%100
    B=[a1,a2,a3,a4,a5,a6,a7,a8,a9,a]
    C=[]
        
    for i in B:
        q=True
        m=2
        while m<=sqrt(i):
            if i%m==0:
                q=False
                break
            m+=1
        if q:
            C.append(i)
    if len(C)>0:
        print(max(C))
    else:
        print("0")
else:
        print("0")
